package com.wmyg.antifake.dao;

import com.wmyg.antifake.bean.Bill;
import com.wmyg.antifake.bean.FactoryBean;
import com.wmyg.antifake.bean.FactorySumInfo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface BillMapper {

    @Insert({"insert into bill(operator,device_id,case_id,creatime,state,boxes) " +
            "value(#{operator},#{deviceId},#{caseId},#{creatime},#{state},#{boxes,javaType=[Ljava.lang.String;,jdbcType=VARCHAR})"})
    @Options(useGeneratedKeys = true, keyProperty = "billId", keyColumn = "bill_id")
    int insert(Bill bill);

    @Update({"update bill set operator=#{operator},device_id=#{deviceId},case_id=#{caseId},creatime=#{creatime},state=#{state},boxes=#{boxes,javaType=[Ljava.lang.String;,jdbcType=VARCHAR} where bill_id=#{billId}"})
    int update(Bill bill);

    @Update({"update bill set state=state+4 where bill_id=#{billId}"})
    int uploaded(Bill bill);

//    Bill selectById(int id);

    List<Bill> selectByNewBill(Bill bill);

    List<Bill> selectInvaildBillsByDeviceId(String deviceId);

    List<Bill> selectNotUploadedBills();

    @Select({"select count(*) from bill where device_id=#{deviceId} and state=3"})
    int selectValidCount(String deviceId);

    @Select({"select count(*) from bill where device_id=#{deviceId} and state<3"})
    int selectInvalidCount(String deviceId);

    @Select({"select count(*) from bill"})
    int selectCountBill();

    List<FactoryBean> selectDevidCount(int factorId);

    List<FactoryBean> selectFactoryCount(int factorId);

    List<Bill>  selectBillList(Bill bill);

    List<FactoryBean> selectFactoryCountSum(int factorId);

    List<FactoryBean> selectFactorycaseIdCount(int factorId);

    List<FactoryBean> selectDeviceInfoCount(int factorId);

    List<FactorySumInfo> selectFactoryByIdSum(int factorId);


}
